# 固定阈值二值化(THRESHOLO_BINARY)
# 非黑即白（>=127==>255;<127==>0）

# 反固定阈值二值化

# 截断阈值二值法

# 超0阈值二值法

# 反超0阈值二值法

import cv2
import matplotlib.pyplot as plt
import numpy as np

fig,axs = plt.subplots(2, 3)

img = cv2.imread('D:/python/opencv-processing/laiya.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# 二值化（灰度图，阈值，二值化加工方式）
ret, b1 = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
ret, b2 = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV)
ret, b3 = cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO)
ret, b4 = cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO_INV)
ret, b5 = cv2.threshold(gray, 127, 255, cv2.THRESH_TRUNC)

axs[0,0].set_title('img')
axs[0,0].imshow(cv2.cvtColor(img,cv2.COLOR_YCrCb2RGB))
axs[0,1].set_title('img1')
axs[0,1].imshow(b1,cmap='gray')
axs[0,2].set_title('img2')
axs[0,2].imshow(b2,cmap='gray')
axs[1,0].set_title('img3')
axs[1,0].imshow(b3,cmap='gray')
axs[1,1].set_title('img4')
axs[1,1].imshow(b4,cmap='gray')
axs[1,2].set_title('img5')
axs[1,2].imshow(b5,cmap='gray')
plt.show()

# cv2.imshow('erzhihua',gray)
# cv2.waitKey(0)
